package com.woniu.rabbit.dlx_model.producer;

import com.woniu.rabbit.dlx_model.exchange.DlxDirectConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Slf4j
public class DlxProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void dlxProducer(String msg) {
        log.info("发送消息：{},发送时间：{}", msg, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        rabbitTemplate.convertAndSend(
                DlxDirectConfig.DLX_DIRECT_NORMAL_EXCHANGE,
                "normal.key",
                msg,
                message ->{
                    message.getMessageProperties().setExpiration("20000");
                    return message;
                });
    }
}
